package com.scm.util;

import com.scm.pojo.PoMain;
import com.scm.pojo.SoItem;
import com.scm.pojo.SoMain;
import com.scm.service.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName Util
 * @Description TODO
 * @Author Xu
 * @Date 2021/7/9 17:57
 * @Version 1.0
 **/
@Component
public class Util {

    @Autowired
    private PoMainService poMainService;

    @Autowired
    private VenderService venderService;

    @Autowired
    private ScmService scmService;

    @Autowired
    private PoItemService poItemService;

    @Autowired
    private ProductService productService;

    @Autowired
    private SoItemService soItemService;

    @Autowired
    private SoMainService soMainService;

    @Autowired
    private CustomerService customerService;


    public static String  getID(List<String> list,String s){
        int i=1001;
        for (String str: list){
            int i1 = Integer.parseInt(str.substring(1));
            if (i==i1){
                i++;
            }

        }
        return s+i;
    }

    public  List<PoMain> show(List<PoMain>list){
        for (PoMain poMain:list){
            poMain.setVenderCode(venderService.getVenderName(poMain.getVenderCode()));
            poMain.setStatus(getStatus(poMain.getStatus()));
            poMain.setAccount(scmService.getUserName(poMain.getAccount()));
        }
        return list;
    }

    public String getStatus(String str){
        if (str.equals("1")){
           return "新增";
        }else if (str.equals("2")){
            return "已付预付款";
        }else if (str.equals("3")){
            return "已入库";
        }else if (str.equals("4")){
            return "已付款";
        }else if (str.equals("5")){
            return "已了结";
        }else {
            return "未知";
        }
    }



    public List<SoMain> showSoMain(List<SoMain> list){
        for (SoMain soMain:list){
            if (soMain.getStatus().equals("3")){
                soMain.setStatus("已出库");
            }else if (soMain.getStatus().equals("4")){
                soMain.setStatus("已收款");
            }else {
                soMain.setStatus(getStatus(soMain.getStatus()));
            }
            soMain.setAccount(scmService.getUserName(soMain.getAccount()));
            soMain.setCustomerCode(customerService.getCustomerName(soMain.getCustomerCode()));
        }
        return list;
    }
    public void flushPoNum(String productCode){
        String poNum = poItemService.getPoNum(productCode);
        productService.flushPoNum(poNum,productCode);
    }
    public void reSoItem(List<SoItem> list){
        for (SoItem soItem:list){
            soItemService.addSoItem(soItem);
            String soNum = soMainService.getSoNum(soItem.getProductCode());
            productService.flushSoNum(soNum,soItem.getProductCode());
        }
    }

}
